package com.blb.thread;

/**
 * 自定义Thread类
 */
public class MyThread extends Thread{

    @Override
    public void run() {
        for (int i = 0;i < 100;i++) {
            //Thread.currentThread().getName() 当前线程的名字
            System.out.println(Thread.currentThread().getName() + "正在运行" + i);
            if(i == 50){
//                Thread.yield();
                try {
                    Thread.sleep(5L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            //当前线程休眠1毫秒
//            try {
//                Thread.sleep(5L);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
        }
    }

    public static void main(String[] args) {

        //创建线程对象
        MyThread myThread = new MyThread();
        myThread.setName("张三");
        MyThread myThread1 = new MyThread();
        myThread1.setName("李四");

        myThread.start();
        myThread1.start();
    }
}
